<template>
	<view class="all">
		<view class="status_bar">
			<!-- 这里是状态栏 -->
		</view>
		<view class="fidexs">
			<view class="all_title">
				<view class="groups" @click="tos">
					<u-icon name="arrow-left" :bold="true" color="rgba(46, 46, 46, .5)" size="20"></u-icon>
					<view class="mod">热销榜</view>
				</view>
				<u-icon name="home" color="rgba(46, 46, 46, .5)" @click="mesg" size="28"></u-icon>
			</view>
			<u-tabs :list="list1" @click="click"></u-tabs>
		</view>
		<view class="top_nav">
			<view class="list_book" v-for="(item,index) in list" @click="pop(item.sourceId)">
				<image :src="item.coverUrl">
				</image>
				<view class="list_book_right">
					<view class="list_book_title">
						{{item.title}}
					</view>
					<u--text :lines="2" line-height="20px" size="12" color="rgba(46,46,46,.5)" :text="item.intro">
					</u--text>
					<view class="list_book_i">
						<text class="names">{{item.authorName}}</text>
						<view class="cupe_t">
							<text :style="item.subCategoryName == undefinde ? 'display:none':'dispaly:block' "
								class="names_c">{{item.subCategoryName}}</text>
							<text class="names_c">{{item.categoryName}}</text>
							<text class="names_t">{{item.allWords | words}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<u-notify message="Hi uView" :show="show"></u-notify>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list1: [{
					name: '周榜',
				}, {
					name: '月榜',
				}, {
					name: '总榜'
				}],
				list: [],
				id: 0,
				num: 1,
				show: false,
				nums: ''
			}
		},
		filters: {
			words(value) {
				return Math.floor(value / 10000) + "万字"
			}

		},
		methods: {
			tos() {
				uni.navigateTo({
					url: "/pages/message/message"
				})
			},
			mesg() {
				uni.navigateBack({
					url: '/pages/message/message'
				})
			},
			click(item) {
				var id = item.index
				this.id = item.index
				this.get(id)
			},
			get(id = 0) {
				uni.$http.get('https://m.taoyuewenhua.com/ajax/book_mall/rank_books?ctype=' + this.nums +
					'&page=0&pageSize=10&brtype=' + id).then(res => {
					this.list = res.data.data.bookList
				}).catch(err => {
					console.log(err)
				})
			},
			pop(id) {
				console.log(id, 999454546)
				uni.navigateTo({
					url: '/pages/books/books?sourceId=' + id
				})
			},
		},
		onLoad(Option) {
			this.nums = Option.nums
			this.get()
		},
		onReachBottom() {
			uni.$http.get('https://m.taoyuewenhua.com/ajax/book_mall/rank_books?ctype=' + this.nums + '&page=' + this.num +
				'&pageSize=10&brtype=' + this.id).then(res => {
				if (res.statusCode == 400) {
					this.show = true;
					return;
				}
				console.log(res, "加载")
				this.num++
				this.list = [...this.list, ...res.data.data.bookList]
			}).catch(err => {
				console.log(err)
			})
		},
	}
</script>

<style lang="scss">
	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
		background-color: #fff;
	}

	.fidexs {
		position: fixed;
		top: var(--status-bar-height);
		right: 0;
		left: 0;
		background: #fff;
		z-index: 11;
		border-bottom: 2rpx solid #eee;
	}

	.all_title {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 30rpx;
		height: 80rpx;
		border-bottom: 2rpx solid #ededed;
		background-color: #fff;

		.groups {
			display: flex;
			align-items: flex-end;

			.mod {
				margin-left: 20rpx;
			}
		}
	}

	.top_nav {
		padding: 180rpx 30rpx 0;

		.list_book {
			display: flex;
			padding: 0rpx 0rpx 30rpx;
			border-bottom: 2rpx solid #ededed;
			margin-top: 30rpx;

			image {
				width: 150rpx;
				height: 200rpx;
				padding-right: 20rpx;
			}

			.list_book_right {
				width: 75%;
				display: flex;
				flex-direction: column;

				.list_book_title {
					color: 2e2e2e;
					font-size: 26rpx;
					font-weight: bolder;
					margin-bottom: 22rpx;
				}

				.list_book_i {
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-top: 22rpx;

					.names {
						font-size: 24rpx;
						color: rgba(46, 46, 46, .5);
					}

					.cupe_t {
						display: flex;

						.names_t {
							text-align: center;
							margin-right: 10rpx;
							padding: 0 12rpx;
							background-color: #f6f6f6;
							font-size: 24rpx;
							color: rgba(46, 46, 46, .5);
						}

						.names_c {
							text-align: center;
							margin-right: 10rpx;
							padding: 0 12rpx;
							background-color: #f6f6f6;
							font-size: 24rpx;
							color: rgba(46, 46, 46, .5);
						}
					}
				}
			}
		}

	}
</style>
